
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统操作日志</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" class="user-search">
      <el-form-item>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table
      size="small"
      :data="DataList"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
    >
      <el-table-column
        align="center"
        sortable
        prop="Content"
        label="详情"
        width="200"
      >
      </el-table-column>
      <el-table-column align="center" sortable label="类型" width="120">
        <template slot-scope="scope">
          <div v-if="scope.row.Type == 0">
            <el-row><el-button  size="mini" type="primary" disabled>登入</el-button></el-row>
          </div>
          <div v-else-if="scope.row.Type == 1">
            <el-row><el-button size="mini" type="success" disabled>新增</el-button></el-row>
          </div>
          <div v-else-if="scope.row.Type == 2">
            <el-row><el-button size="mini" type="info" disabled>编辑</el-button></el-row>
          </div>
          <div  v-else-if="scope.row.Type == 3">
            <el-row><el-button  size="mini" type="danger" disabled>删除</el-button></el-row>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="CreateTime"
        label="添加时间"
        min-width="120"
      >
      </el-table-column>

      <el-table-column label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
             type="success"
              icon="el-icon-edit"
            @click="handleEdit(scope.$index, scope.row)"
            v-permission="['edit', $route]"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <!-- 编辑界面 -->
    <el-dialog
      :title="title"
      :visible.sync="editFormVisible"
      width="50%"
      @click="closeDialog('edit')"
      :close-on-click-modal="false"
    >
      <el-form label-width="80px" ref="editForm" :model="editForm">
       
        <el-form-item label="类型" prop="Type">
          <template>
             <div v-if="editForm.Type == 0">
            <el-row><el-button  size="mini" type="primary" disabled>登入</el-button></el-row>
          </div>
          <div v-else-if="editForm.Type == 1">
            <el-row><el-button size="mini" type="success" disabled>新增</el-button></el-row>
          </div>
          <div v-else-if="editForm.Type == 2">
            <el-row><el-button size="mini" type="info" disabled>编辑</el-button></el-row>
          </div>
          <div  v-else-if="editForm.Type == 3">
            <el-row><el-button  size="mini" type="danger" disabled>删除</el-button></el-row>
          </div>
          </template>
        </el-form-item>

        <el-form-item label="操作时间" prop="CreateTime">
          {{ editForm.CreateTime }}</el-form-item
        >
        <el-form-item label="详情" prop="Content">
          <el-input
            type="textarea"
            :rows="5"
            v-model="editForm.Content"
          ></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// 导入请求方法
import { req, reqjson } from "@/api/axiosFun";

import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
      loading: false, //是显示加载
      title: "添加用户",
      editFormVisible: false, //控制编辑页面显示与隐藏
      // 编辑与添加
      editForm: {
        GuId: "",
        Name: "",
        CreateTime: "",
        Content: "",
        Type: "",
      },

      //数据
      DataList: [],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
    };
  },
  // 注册组件
  components: {
    Pagination,
  },

  /**
   * 数据发生改变
   */
  watch: {},

  /**
   * 创建完毕
   */
  created() {
    this.getdata();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取数据方法
    getdata(parameter) {
      let data = {
        page: this.pageparm.currentPage,
        limit: this.pageparm.pageSize,
      };
      this.loading = true;
      reqjson(
        "post",
        "/SysLogApi/GetLoginLogList?token=" + this.$jsutils.sessionget("token"),
        data
      )
        .then((x) => {
          this.loading = false;
          if (x.success) {
            this.pageparm.currentPage = x.data.CurrentPage;
            this.pageparm.pageSize = x.data.ItemsPerPage;
            this.pageparm.total = x.data.TotalItems;
            this.DataList = x.data.Items;
          }
        })
        .catch((x) => {
          this.loading = false;
          console.log(x);
        });
    },
    // 分页插件事件
    callFather(parm) {

      this.pageparm.currentPage = parm.currentPage;
      this.pageparm.pageSize = parm.pageSize;
      this.getdata(this.pageparm);
    },
    //搜索事件
    search() {
      this.getdata(this.formInline);
    },

    //显示编辑界面
    handleEdit(index, row) {
      this.editFormVisible = true;
      if (!!row) {
        this.title = "查看详情";
        this.editForm = row;
      }
    },

    gettype(type) {
      switch (type) {
        case 0:
          return `<el-row><el-button type=primary disabled>登入</el-button></el-row>`;

        case 1:
          return `<el-row><el-button type=success disabled>新增</el-button></el-row>`;
        case 2:
          return `<el-row><el-button type=info disabled>编辑</el-button></el-row>`;
        case 3:
          return `<el-row><el-button type=danger disabled>删除</el-button></el-row>`;
      }
    },

    // 关闭编辑、增加弹出框
    closeDialog(dialog) {
      if (dialog == "edit") {
        this.editFormVisible = false;
      }
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 